<?php

namespace App\Http\Controllers\Admin;


use App\Models\Admin\Video;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class VideoController extends Controller
{
    //视频视图
    public function index(){

        $videos = Video::all();

       return view('admin/video')->with('videos',$videos);
    }

    //视频添加
    public function create(){

        return view('admin/video_create');
    }
    //视频添加数据库
    public function store(Request $request){
        $videos=new Video();
        $videos->video = $request->video;
        $videos->content = $request->content;
        if($videos->save()){
            return redirect('admin/video');
        }else{
            return redirect()->back();
        }
    }
    //视频修改
    public function edit($id){

        $videos= Video::find($id);

        return view('admin/video_edit')->with('videos',$videos);

    }
    //视频修改提交到数据库
    public function update(Request $request,$id){
        $videos= Video::find($id);
        $videos->video = $request->get('video');
        $videos->content = $request->get('content');
        $videos->save();
        return redirect('admin/video');

    }
    //视频删除
    public function destroy($id){

        $videos = Video::find($id);
        if($videos->delete()){
            return redirect('admin/video');
        }else{
            return redirect()->back();
        }
    }
}
